package com.holyn.guofang.presenter.login;

import com.holyn.guofang.model.webhttp.RetrofitManager;
import com.holyn.guofang.model.webhttp.observable.UserUnLoginObservable;
import com.holyn.guofang.model.webhttp.wo.StatusWo;
import com.holyn.guofang.model.webhttp.wo.UserInfoWo;
import com.holyn.guofang.presenter.BaseView;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Consumer;

/**
 * Created by Holyn on 2017/6/9.
 */

public class RegisterPresenter extends RegisterContract.Presenter {

    private RegisterContract.View registerView;

//    private RegisterObservable registerObservable;
    private final UserUnLoginObservable userUnLoginObservable;

    public RegisterPresenter(BaseView baseView) {
        super(baseView);
        userUnLoginObservable = RetrofitManager.getCommonObservable(UserUnLoginObservable.class);
    }

    @Override
    public void addViewListener(RegisterContract.View view) {
        this.registerView = view;
    }

    @Override
    public void postRegister(String userName, String password, Integer checkMethod, String mobile,
                             String email, String name, String validCode, Integer isInstitution, int requestAction) {
        getCommonObservable(requestAction, userUnLoginObservable.register(userName, password, checkMethod, mobile, email, name, validCode, isInstitution))
                .subscribe(new Consumer<StatusWo>() {
                    @Override
                    public void accept(@NonNull StatusWo statusWo) throws Exception {
                        registerView.responseSuccess(requestAction, statusWo);
                    }
                });
    }

    @Override
    public void postRegisterB(Integer regType, String mainMobile, String mobile, String validCode, Integer isInstitution, int requestAction) {
        getCommonObservable(requestAction, userUnLoginObservable.registerb(regType, mainMobile, mobile, validCode, isInstitution))
                .subscribe(new Consumer<StatusWo>() {
                    @Override
                    public void accept(@NonNull StatusWo statusWo) throws Exception {
                        registerView.responseSuccess(requestAction, statusWo);
                    }
                });
    }

    @Override
    public void postRegisterCode(String userName, Integer checkMethod, String equipmentCode, int requestAction) {
        getCommonObservable(requestAction, userUnLoginObservable.registerCode(userName, checkMethod, equipmentCode))
                .subscribe(new Consumer<StatusWo>() {
                    @Override
                    public void accept(@NonNull StatusWo statusWo) throws Exception {
                        registerView.responseSuccess(requestAction, statusWo);
                    }
                });
    }

    @Override
    public void postRegisterCodeB(String userName, String equipmentCode, int requestAction) {
        getCommonObservable(requestAction, userUnLoginObservable.registerCodeb(userName, equipmentCode))
                .subscribe(new Consumer<StatusWo>() {
                    @Override
                    public void accept(@NonNull StatusWo statusWo) throws Exception {
                        registerView.responseSuccess(requestAction, statusWo);
                    }
                });

    }
}
